<template>
  <div class="publish-page">
    <div class="app-header">
      <div class="back-btn" @click="goBack">
        <i class="fas fa-arrow-left"></i>
      </div>
      <div class="app-title">发布内容</div>
    </div>

    <div class="container">
      <div class="welcome-section">
        <div class="welcome-icon">
          <i class="fas fa-plus"></i>
        </div>
        <h1>分享到邻里社区</h1>
        <p class="subtitle">选择您想要分享的内容类型</p>
      </div>

      <div class="selection-area">
        <div class="category-title">社区发布</div>

        <div class="selection-card" @click="selectType('discussion')">
          <div class="card-icon">
            <i class="fas fa-comments"></i>
          </div>
          <div class="card-content">
            <h3 class="card-title">发起讨论</h3>
            <p class="card-desc">分享想法、观点或提出问题</p>
          </div>
          <div class="card-arrow">
            <i class="fas fa-chevron-right"></i>
          </div>
        </div>

        <div class="selection-card" @click="selectType('help')">
          <div class="card-icon">
            <i class="fas fa-hands-helping"></i>
          </div>
          <div class="card-content">
            <h3 class="card-title">寻求帮助</h3>
            <p class="card-desc">需要邻居的帮助？发布求助信息</p>
          </div>
          <div class="card-arrow">
            <i class="fas fa-chevron-right"></i>
          </div>
        </div>

        <div class="category-title">交易发布</div>

        <div class="selection-card" @click="selectType('sell')">
          <div class="card-icon">
            <i class="fas fa-tag"></i>
          </div>
          <div class="card-content">
            <h3 class="card-title">出售物品</h3>
            <p class="card-desc">将闲置物品转让给需要的邻居</p>
          </div>
          <div class="card-arrow">
            <i class="fas fa-chevron-right"></i>
          </div>
        </div>

        <div class="selection-card" @click="selectType('rent')">
          <div class="card-icon">
            <i class="fas fa-exchange-alt"></i>
          </div>
          <div class="card-content">
            <h3 class="card-title">出租物品</h3>
            <p class="card-desc">出租您不常用的物品，赚取额外收入</p>
          </div>
          <div class="card-arrow">
            <i class="fas fa-chevron-right"></i>
          </div>
        </div>
      </div>

      <div class="safe-area"></div>
    </div>

    <!-- Toast 提示 -->
    <div v-if="showToast" class="toast-message" :class="{ 'toast-visible': showToast }">
      {{ toastMessage }}
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';

export default {
  name: 'PublishPage',
  setup() {
    const router = useRouter();
    const showToast = ref(false);
    const toastMessage = ref('');

    const typeNames = {
      'discussion': '发起讨论',
      'help': '寻求帮助',
      'sell': '出售物品',
      'rent': '出租物品'
    };

    const goBack = () => {
      router.go(-1);
    };

    const selectType = (type) => {

      if(type === 'discussion'||type === 'help') {
        router.push(`/start${type}`)
      }
      else router.push(`/startsell/${type}`)
      toastMessage.value = `准备${typeNames[type]}...`;
      showToast.value = true;

      setTimeout(() => {
        showToast.value = false;
        console.log(`跳转到发布页面: ${type}`);
      }, 2000);
    };

    const addTouchFeedback = () => {
      const cards = document.querySelectorAll('.selection-card');
      cards.forEach(card => {
        card.addEventListener('touchstart', function() {
          this.style.transform = 'scale(0.98)';
        });

        card.addEventListener('touchend', function() {
          this.style.transform = '';
        });

        card.addEventListener('touchcancel', function() {
          this.style.transform = '';
        });
      });
    };

    onMounted(() => {
      addTouchFeedback();
    });

    return {
      goBack,
      selectType,
      showToast,
      toastMessage
    };
  }
}
</script>

<style scoped>
.publish-page {
  min-height: 100vh;
  background-color: #f8f9fa;
  color: #2c3e50;
  overflow-x: hidden;
  position: relative;
  font-family: 'Nunito', 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
}

.publish-page * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 顶部导航栏 */
.app-header {
  position: sticky;
  top: 0;
  height: 60px;
  background-color: #4267F4;
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s;
}

.back-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.app-title {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: white;
  padding-right: 40px;
}

.container {
  width: 100%;
  max-width: 100%;
  padding: 20px 16px;
  margin: 0 auto;
}

.welcome-section {
  text-align: center;
  margin: 20px 0 30px;
  position: relative;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  background-color: #4267F4;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 15px;
  color: white;
  font-size: 32px;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 14px;
  color: #7f8c8d;
  line-height: 1.5;
}

.selection-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.category-title {
  font-size: 16px;
  font-weight: 600;
  color: #4267F4;
  margin: 20px 0 12px;
  padding-left: 8px;
}

.selection-card {
  width: 100%;
  height: auto;
  min-height: 80px;
  background-color: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  border-left: 4px solid #4267F4;
  cursor: pointer;
}

.selection-card:hover {
  box-shadow: 0 4px 12px rgba(66, 103, 244, 0.15);
  transform: translateY(-2px);
}

.selection-card:active {
  transform: scale(0.98);
}

.card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 20px;
  flex-shrink: 0;
  background-color: #EDF2FD;
  color: #4267F4;
}

.card-content {
  flex: 1;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #2c3e50;
}

.card-desc {
  font-size: 13px;
  color: #7f8c8d;
  line-height: 1.4;
}

.card-arrow {
  color: #bdc3c7;
  font-size: 14px;
  margin-left: 8px;
  flex-shrink: 0;
}

/* 底部安全区域填充 */
.safe-area {
  height: constant(safe-area-inset-bottom);
  height: env(safe-area-inset-bottom);
}

/* Toast 消息 */
.toast-message {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background-color: #4267F4;
  color: white;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(66, 103, 244, 0.3);
  z-index: 1000;
  font-weight: 500;
  transition: all 0.3s ease;
  opacity: 0;
  font-size: 14px;
}

.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.selection-card {
  animation: fadeIn 0.4s ease forwards;
}

.selection-card:nth-child(1) { animation-delay: 0.1s; }
.selection-card:nth-child(2) { animation-delay: 0.2s; }
.selection-card:nth-child(3) { animation-delay: 0.3s; }
.selection-card:nth-child(4) { animation-delay: 0.4s; }

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
  .publish-page {
    background-color: #1a1d21;
    color: #ecf0f1;
  }

  .app-header {
    background-color: #4267F4;
  }

  .welcome-icon {
    background-color: #4267F4;
  }

  h1, .card-title {
    color: #ecf0f1;
  }

  .subtitle, .card-desc {
    color: #bdc3c7;
  }

  .selection-card {
    background-color: #2c3e50;
    border-left-color: #4267F4;
  }

  .card-icon {
    background-color: #34495e;
    color: #4267F4;
  }
}
</style>